<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建日期" prop="createDate">
        <el-date-picker
          v-model="queryParams.createDate"
          type="date"
          placeholder="选择日期"
          style="width: 205px"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['pcplan:orderResourcesYs:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['pcplan:orderResourcesYs:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table height="calc(100vh - 300px)" v-loading="loading" :data="orderResourcesYsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="公司代码" align="center" prop="factoryCode" />
      <el-table-column label="公司名称" align="center" prop="factoryName" >
      </el-table-column>
      <el-table-column label="订单类别" align="center" prop="orderType" >
        <template slot-scope="scope">
          <span v-if="scope.row.orderType=='1'">
            正式
          </span>
          <span v-if="scope.row.orderType=='0'">
            预测
          </span>
        </template>
      </el-table-column>
<!--      <el-table-column label="特殊要求" align="center" prop="specialRequirements" />-->
      <el-table-column label="合同号" align="center" prop="hth" width="140"/>
      <el-table-column label="订单号" align="center" prop="orderNo" width="160"/>
      <el-table-column label="产品状态" align="center" prop="productState" >
        <template slot-scope="scope">
          <span v-if="scope.row.productState=='1'">
            正式
          </span>
          <span v-if="scope.row.productState=='2'">
            试制
          </span>
          <span v-if="scope.row.productState=='3'">
            研发
          </span>
          <span v-if="scope.row.productState=='4'">
            未立项
          </span>
        </template>
      </el-table-column>
<!--      <el-table-column label="产品编码" align="center" prop="productCode" />-->
<!--      <el-table-column label="产品名称" align="center" prop="productName" />-->

<!--      <el-table-column label="产品类型" align="center" prop="productType" />-->
      <el-table-column label="物料编码" align="center" prop="itemId" width="120"/>
      <el-table-column label="物料名称" align="center" prop="itemName" width="120"/>
      <el-table-column label="物料规格" align="center" prop="itemSpec" width="120"/>
      <el-table-column label="订单数量" align="center" prop="orderNumber" />
<!--      <el-table-column label="质量状态" align="center" prop="qualityStatus" width="120"/>-->
<!--      <el-table-column label="使用状态" align="center" prop="usageStatus" width="120"/>-->
      <el-table-column label="单位" align="center" prop="unit"/>
<!--      <el-table-column label="单台用量" align="center" prop="dtyl" width="80"/>-->
<!--      <el-table-column label="订单用量" align="center" prop="totalOrderUsage" width="80"/>-->
      <el-table-column label="可用库存数量" align="center" prop="kcNum" width="120"/>
      <el-table-column label="本次锁账数量" align="center" prop="lockedAccountQuantity" width="120"/>
      <el-table-column label="仓储缺件数量" align="center" prop="warehouseShortageQuantity" width="120"/>
      <el-table-column label="锁账时间" align="center" prop="lockedTime" width="120"/>
      <el-table-column label="仓库代码" align="center" prop="warehouseCode" />
      <el-table-column label="仓库名称" align="center" prop="stockName" />
      <el-table-column label="库区代码" align="center" prop="kuquCode" />
      <el-table-column label="库区名称" align="center" prop="kuquName" />
      <el-table-column label="库位编码" align="center" prop="kwbm" />
      <el-table-column label="库位数量" align="center" prop="kwNum" />
      <el-table-column label="创建人" align="center" prop="createBy" width="150"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="150"/>
      <el-table-column label="备注" align="center" prop="remark" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['pcplan:orderResourcesYs:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['pcplan:orderResourcesYs:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单资源验算对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="特殊要求" prop="specialRequirements">
          <el-input v-model="form.specialRequirements" placeholder="请输入特殊要求" />
        </el-form-item>

        <el-form-item label="产品状态" prop="productState">
          <el-select v-model="form.productState" placeholder="请选择产品状态" clearable>
            <el-option
              v-for="item in this.prodcteState"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="订单状态" prop="orderState">
          <el-select v-model="form.orderState" placeholder="请选择产品状态" clearable>
            <el-option
              v-for="item in this.orderState"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="订单撤销标记" prop="orderRevocFlag">
          <el-select v-model="form.orderRevocFlag" placeholder="请选择产品状态" clearable>
            <el-option
              v-for="item in this.zfbj"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="审核人员" prop="auditUser">
          <el-input v-model="form.auditUser" placeholder="请输入审核人员" />
        </el-form-item>
        <el-form-item label="审核时间" prop="auditTime">
          <el-date-picker clearable
                          v-model="form.auditTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核车间" prop="auditWorkshop">
          <el-input v-model="form.auditWorkshop" placeholder="请输入审核车间" />
        </el-form-item>
        <el-form-item label="配置类型" prop="auditWorkshop">
          <el-input v-model="form.auditWorkshop" placeholder="请输入配置类型" />
        </el-form-item>

        <el-form-item label="是否急单" prop="isEmergency">
          <el-select v-model="form.isEmergency" placeholder="请选择产品状态" clearable>
            <el-option
              v-for="item in this.sfjd"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="加急确认时间" prop="emeConfirmTime">
          <el-date-picker clearable
                          v-model="form.emeConfirmTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择加急确认时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOrderResourcesYs,
  getOrderResourcesYs,
  delOrderResourcesYs,
  addOrderResourcesYs,
  updateOrderResourcesYs
} from "@/api/pcplan/orderResourcesYs";
import moment from "moment";

export default {
  name: "OrderResourcesYs",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单资源验算表格数据
      orderResourcesYsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        factoryCode: null,
        factoryName: null,
        orderType: null,
        specialRequirements: null,
        hth: null,
        orderNo: null,
        productState: null,
        orderState: null,
        ifOrderUndo: null,
        auditUser: null,
        auditTime: null,
        auditWorkshop: null,
        configType: null,
        orderNumber: null,
        warehouseCode: null,
        kcNum: null,
        kwbm: null,
        kwNum: null,
        kcOrderNum: null,
        syOrderNum: null,
        deliveryDate: null,
        noPcNum: null,
        yuPcNum: null,
        pcNum: null,
        scNum: null,
        finishNum: null,
        pcJss: null,
        productOrderType: null,
        productModel: null,
        baseItemNum: null,
        pzkItemNum: null,
        zcXzNo: null,
        configNo: null,
        configRequire: null,
        oDeliveryDate: null,
        color: null,
        pcState: null,
        cccNotice: null,
        gxbNotice: null,
        rejectReason: null,
        clientNo: null,
        truckType: null,
        country: null,
        user: null,
        jyPcCj: null,
        slDpLx: null,
        noticeOrderNo: null,
        isEmergency: null,
        series: null,
        qdxs: null,
        newCarType: null,
        newCarInstruction: null,
        tecConfirmState: null,
        tecConfirmInfo: null,
        orderTime: null,
        createDate: new Date(),
      },
      // 表单参数
      form: {},
      prodcteState: [{
        value: '1',
        label: '正式'
      }, {
        value: '2',
        label: '试制'
      },{
        value: '3',
        label: '研发'
      },{
        value: '4',
        label: '未立项'
      }],
      orderState: [{
        value: '0',
        label: '未执行'
      }, {
        value: '1',
        label: '已执行'
      }],
      zfbj: [{
        value: '0',
        label: '作废'
      }, {
        value: '1',
        label: '启用'
      }],
      sfjd: [{
        value: '0',
        label: '否'
      }, {
        value: '1',
        label: '是'
      }],
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单资源验算列表 */
    getList() {
      this.loading = true;
      this.queryParams.createDate = moment.utc(this.queryParams.createDate).local().format('YYYY-MM-DD')
      if(this.queryParams.createDate == 'Invalid date'){
        this.queryParams.createDate = null
      }
      listOrderResourcesYs(this.queryParams).then(response => {
        this.orderResourcesYsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        factoryCode: null,
        factoryName: null,
        orderType: null,
        specialRequirements: null,
        hth: null,
        orderNo: null,
        productState: null,
        orderState: null,
        ifOrderUndo: null,
        auditUser: null,
        auditTime: null,
        auditWorkshop: null,
        configType: null,
        orderNumber: null,
        warehouseCode: null,
        kcNum: null,
        kwbm: null,
        kwNum: null,
        kcOrderNum: null,
        syOrderNum: null,
        deliveryDate: null,
        noPcNum: null,
        yuPcNum: null,
        pcNum: null,
        scNum: null,
        finishNum: null,
        pcJss: null,
        productOrderType: null,
        productModel: null,
        baseItemNum: null,
        pzkItemNum: null,
        zcXzNo: null,
        configNo: null,
        configRequire: null,
        oDeliveryDate: null,
        color: null,
        pcState: null,
        cccNotice: null,
        gxbNotice: null,
        rejectReason: null,
        clientNo: null,
        truckType: null,
        country: null,
        user: null,
        jyPcCj: null,
        slDpLx: null,
        noticeOrderNo: null,
        isEmergency: null,
        series: null,
        qdxs: null,
        newCarType: null,
        newCarInstruction: null,
        tecConfirmState: null,
        tecConfirmInfo: null,
        orderTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单资源验算";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrderResourcesYs(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单资源验算";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrderResourcesYs(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrderResourcesYs(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除订单资源验算编号为"' + ids + '"的数据项？').then(function() {
        return delOrderResourcesYs(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pcplan/orderResourcesYs/export', {
        ...this.queryParams
      }, `orderResourcesYs_${new Date().getTime()}.xlsx`)
    },

  }
};
</script>
